
function merchantService($http) {

    //find all merchants
    function findAllMerchantList(callback) {
        $http.get("/o2o/admin/merchants")
            .then(function (res) {
                console.log(res);
                callback(null, res.data);
            })
            .catch(function (err) {
                console.error(err);
                callback(err, null);
            });
    }

    //find merchants by status
    function findMerchantListByStatus(status, callback) {
        $http.get("/o2o/admin/merchants/"+status)
            .then(function (res) {
                console.log(res);
                callback(null, res.data);
            })
            .catch(function (err) {
                console.error(err);
                callback(err, null);
            });
    }

    //according to the id
    function findMerchantListById(id, callback) {
        $http.get("/o2o/admin/merchant/"+id)
            .then(function (res) {
                console.log(res);
                callback(null, res.data);
            })
            .catch(function (err) {
                console.error(err);
                callback(err, null);
            });
    }

    //according to the id
    function updateStatus(merchant,callback) {
        var postData = { 
            "_id": merchant._id,
            "status":merchant.status,
            "reason":merchant.reason 
        };
        var config = {};
        $http.post("/o2o/admin/merchant", postData,config)
            .then(function (res) {
                console.log(res);
                callback(null, res.data);
            })
            .catch(function (err) {
                console.error(err);
                callback(err, null);
            });
    }
    return {
        findAllMerchantList: findAllMerchantList,
        findMerchantListByStatus: findMerchantListByStatus,
        findMerchantListById: findMerchantListById,
        updateStatus:updateStatus
    }
}

module.exports = merchantService;